package com.ra.landlord;

import java.util.Date;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Transient;

/**
 * 分摊单元
 * 
 * @author colin 
 * Date: 2015-03-15
 */
@Entity
public class ShareUnit {
	
	private Integer id;
	
	// 分摊名称
	private String name;
	
	// 楼房
	private Building building;
	
	// 收费规则
	private List<FeeRule> feeRules;
	
	//分摊单元
	private List<RoomShareUnit> roomShareUnits;
	
	// 描述
	private String description;
	
	// transient, 指定某一计费规则下， 该规则的本次读表数据
	private Meter currentMeter;

	// transient, 指定某一计费规则下， 该规则的上次读表数据
	private Meter lastMeter;
	
	// transient
	private Meter lastLastMeter;
	
	// 创建时间
	private Date createTime;
	
	@Id
	@GeneratedValue
	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}
	
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}
	
	@ManyToOne(targetEntity=Building.class, fetch=FetchType.LAZY, optional=false)
	@JoinColumn(name = "building_id")
	public Building getBuilding() {
		return building;
	}

	public void setBuilding(Building building) {
		this.building = building;
	}

	@OneToMany(targetEntity=FeeRule.class, fetch=FetchType.LAZY, cascade=CascadeType.ALL, orphanRemoval=true, mappedBy="shareUnit")
	public List<FeeRule> getFeeRules() {
		return feeRules;
	}

	public void setFeeRules(List<FeeRule> feeRules) {
		this.feeRules = feeRules;
	}
	
	@Transient
	public Meter getCurrentMeter() {
		return currentMeter;
	}

	public void setCurrentMeter(Meter currentMeter) {
		this.currentMeter = currentMeter;
	}

	@Transient
	public Meter getLastMeter() {
		return lastMeter;
	}

	public void setLastMeter(Meter lastMeter) {
		this.lastMeter = lastMeter;
 	}
	
	@OneToMany(targetEntity=RoomShareUnit.class, fetch=FetchType.LAZY, cascade=CascadeType.ALL, orphanRemoval=true, mappedBy="shareUnit")
	public List<RoomShareUnit> getRoomShareUnits() {
		return roomShareUnits;
	}

	public void setRoomShareUnits(List<RoomShareUnit> roomShareUnits) {
		this.roomShareUnits = roomShareUnits;
	}
	
	@Temporal(TemporalType.TIMESTAMP)
	public Date getCreateTime() {
		return createTime;
	}

	public void setCreateTime(Date createTime) {
		this.createTime = createTime;
	}

	@Transient
	public Meter getLastLastMeter() {
		return lastLastMeter;
	}

	public void setLastLastMeter(Meter lastLastMeter) {
		this.lastLastMeter = lastLastMeter;
	}

}
